package com.taotao.Controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.pojo.TbItemCat;
import com.taotao.service.ItemCatService;

@Controller
@RequestMapping("/item/cat")
public class ItemCatController {
	
	@Autowired
	private ItemCatService itemCatService;
	
	@SuppressWarnings({"unchecked","rawtypes"})
	@RequestMapping("/list")
	@ResponseBody
	public List categoryList(@RequestParam(defaultValue = "0")Long id) {
		List<TbItemCat> itemCatList = itemCatService.getItemCatList(id);
		List list=new ArrayList();
		for(TbItemCat cat: itemCatList) {
			Map node= new HashMap();
			node.put("id",cat.getId());
			node.put("text", cat.getName());
			node.put("state",cat.getIsParent()?"closed":"open");
			list.add(node);
	
		}
		return list;
	}
}
